﻿namespace JelloPhysics
{
    using Microsoft.Xna.Framework;
    using System;

    public class AABB
    {
        public Vector2 Max;
        public Vector2 Min;
        public PointValidity Validity;

        public AABB()
        {
            this.Min = this.Max = Vector2.Zero;
            this.Validity = PointValidity.Invalid;
        }

        public AABB(ref Vector2 minPt, ref Vector2 maxPt)
        {
            this.Min = minPt;
            this.Max = maxPt;
            this.Validity = PointValidity.Valid;
        }

        public void clear()
        {
            this.Min.X = this.Max.X = this.Min.Y = this.Max.Y = 0f;
            this.Validity = PointValidity.Invalid;
        }

        public bool contains(ref Vector2 pt)
        {
            if (this.Validity == PointValidity.Invalid)
            {
                return false;
            }
            return ((((pt.X >= this.Min.X) && (pt.X <= this.Max.X)) && (pt.Y >= this.Min.Y)) && (pt.Y <= this.Max.Y));
        }

        public void expandToInclude(ref Vector2 pt)
        {
            if (this.Validity == PointValidity.Valid)
            {
                if (pt.X < this.Min.X)
                {
                    this.Min.X = pt.X;
                }
                else if (pt.X > this.Max.X)
                {
                    this.Max.X = pt.X;
                }
                if (pt.Y < this.Min.Y)
                {
                    this.Min.Y = pt.Y;
                }
                else if (pt.Y > this.Max.Y)
                {
                    this.Max.Y = pt.Y;
                }
            }
            else
            {
                this.Min = this.Max = pt;
                this.Validity = PointValidity.Valid;
            }
        }

        public bool intersects(ref AABB box)
        {
            bool flag = (this.Min.X <= box.Max.X) && (this.Max.X >= box.Min.X);
            bool flag2 = (this.Min.Y <= box.Max.Y) && (this.Max.Y >= box.Min.Y);
            return (flag && flag2);
        }

        public enum PointValidity
        {
            Invalid,
            Valid
        }
    }
}

